INotifyPropertyChanged
, ICloneable
, and IChangeDataValue interfaces.
Visual Basic (Declaration) | |
---|---|
Public Class GraphLinksModelLinkData (Of NodeKey,PortKey) Implements IChangeDataValue, ICloneable, INotifyPropertyChanged |
C# | |
---|---|
public class GraphLinksModelLinkData<NodeKey,PortKey> : IChangeDataValue, ICloneable, INotifyPropertyChanged |
- NodeKey
- the Type of a value uniquely identifying a node data in the model
- PortKey
- the Type of an optional value that helps distinguish different "ports" on a node
This provides a standard implementation of Northwoods.GoXam.Model.GraphLinksModel<NodeType,NodeKey,PortKey,LinkType> data that represents links, including properties that are "references" to the two nodes at each end of the link and optional "port" parameter information at both ends. You can use this class if you do not already have your own application class holding information about links and if you want to inherit from an existing class so that you can just add your own properties. Here's a simple example:
[Serializable] public class MyLinkData : GraphLinksModelLinkData<String, String> { public double Cost { get { return _Cost; } set { if (_Cost != value) { double old = _Cost; _Cost = value; RaisePropertyChanged("Cost", old, value); } } } private double _Cost; }This associates a number with each link so that you can bind values to this property in a
DataTemplate
. For example, look at the TextBlock
's binding of Text
in this template: <DataTemplate x:Key="LinkTemplate"> <go:LinkPanel go:Part.SelectionElementName="Path" go:Part.SelectionAdorned="True"> <go:LinkShape x:Name="Path" go:LinkPanel.IsLinkShape="True" Stroke="Black" StrokeThickness="1" /> <Path Fill="Black" go:LinkPanel.ToArrow="Standard" /> <TextBlock Text="{Binding Path=Data.Cost}" /> </go:LinkPanel> </DataTemplate>(In Silverlight, replace the
go:LinkShape
with Path
.)
Note that property setters need to raise the model's Changed event, so that the model knows about changes in the data and can then update the diagram. You should call RaisePropertyChanged only when the value has actually changed, and you should pass both the previous and the new values, in order to support undo/redo.
For WPF the properties that you define should also be serializable, in order for the data to be copiable, especially to and from the clipboard. For both Silverlight and WPF you should override the Clone method.
In the sample above, the NodeKey is declared to be a string, which is used as the way to uniquely refer to node data. The PortKey is declared to be a string, which is useful if you want to distinguish between multiple "ports" on a single node. However, if your nodes only have a single port, you can ignore the port parameter information, and the PortKey type does not really matter, although string
is recommended for compatibility with the implementation of Node methods that deal with ports.
This class is not useful with Northwoods.GoXam.Model.GraphModel<NodeType,NodeKey> or Northwoods.GoXam.Model.TreeModel<NodeType,NodeKey>.
System.Object
Northwoods.GoXam.Model.GraphLinksModelLinkData<NodeKey,PortKey>
Northwoods.GoXam.Model.UniversalLinkData